package com.example.personnel_management_system.service.Impl;

import com.example.personnel_management_system.entity.Employee;
import com.example.personnel_management_system.mapper.EmployeeMapper;
import com.example.personnel_management_system.service.IEmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
@Service
public class EmployeeServiceImpl implements IEmployeeService {
    @Autowired
    private EmployeeMapper employeeMapper;
    @Override
    public Integer insert(Employee employee) {
        employee.seteStatus(0);
        return employeeMapper.insert(employee);
    }

    @Override
    public Integer update(Employee employee) {
        return employeeMapper.update(employee);
    }

    @Override
    public List<Employee> findByeSatus(Integer eStatus) {
        return employeeMapper.findByeSatus(eStatus);
    }

    @Override
    public List<Employee> findall() {
        return employeeMapper.findall();
    }

    @Override
    public Employee findByeID(Integer eID) {
        return employeeMapper.findByeID(eID);
    }

    @Override
    public List<Employee> findlike(Employee employee, String  begintime, String endtime) throws ParseException {
        SimpleDateFormat sim=new SimpleDateFormat("yyyy-MM-dd");
        Date begin=null;
        if(begintime!=null&&!begintime.equals(""))
            begin=new Date(sim.parse(begintime).getTime());
        Date end=null;
        if(endtime!=null&&!endtime.equals(""))
            end= new Date(sim.parse(endtime).getTime());
        return employeeMapper.findlike(employee,begin,end);
    }

    @Override
    public List<Employee> findExcludeeStatus(Integer eStatus) {
        return employeeMapper.findExcludeeStatus(eStatus);
    }
}
